<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>查询书籍</title>
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@4.6.2/dist/css/bootstrap.min.css" integrity="sha384-xOolHFLEh07PJGoPkLv1IbcEPTNtaed2xpHsD9ESMhqIYd0nLMwNLD69Npy4HI+N" crossorigin="anonymous">
</head>
<body>
<div class="container my-2">
    <table border="1" class="table table-striped table-responsive-md">
        <thead>
        <tr>
            <th><a th:href="@{'/page/' + ${currentPage} + '?sortField=id&sortDir=' + ${reverseSortDir}}">id</a></th>

            <th><a th:href="@{'/page/' + ${currentPage} + '?sortField=name&sortDir=' + ${reverseSortDir}}">书名</a></th>
            <th><a th:href="@{'/page/' + ${currentPage} + '?sortField=author&sortDir=' + ${reverseSortDir}}">作者</a></th>
            <th><a th:href="@{'/page/' + ${currentPage} + '?sortField=publisher&sortDir=' + ${reverseSortDir}}">出版社</a></th>
            <th><a th:href="@{'/page/' + ${currentPage} + '?sortField=bookNumber&sortDir=' + ${reverseSortDir}}">书籍编号</a></th>
            <th><a th:href="@{'/page/' + ${currentPage} + '?sortField=bookType&sortDir=' + ${reverseSortDir}}">书籍种类</a></th>
            <th><a th:href="@{'/page/' + ${currentPage} + '?sortField=price&sortDir=' + ${reverseSortDir}}">销售价格</a></th>
            <th>操作</th>
        </tr>

        </thead>
        <tbody>
        <tr th:each="book : ${books}">
            <td th:text="${book.id}"></td>
            <td th:text="${book.name}"></td>
            <td th:text="${book.author}"></td>
            <td th:text="${book.publisher}"></td>
            <td th:text="${book.bookNumber}"></td>
            <td th:text="${book.bookType}"></td>
            <td th:text="${book.price}"></td>
            <td>
                <a th:href="@{/updateBook/{id}(id=${book.id})}" class="btn btn-primary">修改</a>
                <a th:href="@{/deleteBook/{id}(id=${book.id})}" class="btn btn-danger">删除</a>
            </td>

        </tr>

        </tbody>

    </table>

    <div th:if = "${totalPages > 1}">
        <div class = "row col-sm-10">
            <div class = "col-sm-3">
                Total Rows: [[${totalItems}]]
            </div>

            <div class = "col-sm-5">
					<span th:each="i: ${#numbers.sequence(1, totalPages)}">
						<a th:if="${currentPage != i}" th:href="@{'/page/' + ${i}+ '?sortField=' + ${sortField} + '&sortDir=' + ${sortDir}}">[[${i}]]</a>
						<span th:unless="${currentPage != i}">[[${i}]]</span>  &nbsp; &nbsp;
					</span>
            </div>

            <div class = "col-sm-1">
                <a th:if="${currentPage < totalPages}" th:href="@{'/page/' + ${currentPage + 1}+ '?sortField=' + ${sortField} + '&sortDir=' + ${sortDir}}">下一页</a>
                <span th:unless="${currentPage < totalPages}">下一页</span>
            </div>

            <div class="col-sm-1">
                <a th:if="${currentPage < totalPages}" th:href="@{'/page/' + ${totalPages}+ '?sortField=' + ${sortField} + '&sortDir=' + ${sortDir}}">最后一页</a>
                <span th:unless="${currentPage < totalPages}">最后一页</span>
            </div>
        </div>
    </div>

</div>


</body>
</html>